import { Dictionary } from "../../utils/dictionary";
import { bagEntity } from "./bagEntity";

/**
 * @Author: 陈瑞鹏
 * @Date:   2023-01-28 15:54:47
 * @Last Modified by:   陈瑞鹏
 * @Last Modified time: 2023-02-01 11:45:46
 */
export default class bagCtr {

  private static _ins: bagCtr = null;

  public static get ins(): bagCtr {
    if (this._ins == null) {
      this._ins = new bagCtr();
    }
    return this._ins;
  }

  public bagDic: Dictionary<any, bagEntity>;

  public curEny: bagEntity = null;

  public bagArr: bagEntity[] = [];

  public initTp(list) {
    this.bagDic = new Dictionary();
    list.forEach(element => {
      if (element) {
        let bagEny: bagEntity = new bagEntity();
        bagEny.init(element);
        this.bagDic.set(bagEny.id, bagEny);
      }
    });
  }

  public initData(val) {
    // console.log(val);
    val.forEach(element => {
      if (this.bagDic.get(element.id)) {
        this.bagDic.get(element.id).time = element.time || 0;
      }
    });
  }

  /**
   * 重置
   */
  reset() {
    this.isSpeedAdd = false;
    this.isGoldAdd = false;
    this.isDelay = false;
    this.offerTime = 0;
    this.isRecover = false;
  }

  hpId: number = 0;
  isSpeedAdd: boolean = false; //是否使用了草鞋 加速
  isGoldAdd: boolean = false; //
  isDelay: boolean = false;
  offerTime: number = 0;
  isRecover: boolean = false;

  recoverTime: number = 0;
  /**
   * 所有友方单位增加30%移速
   */
  public get speedAdd() {
    if (this.isSpeedAdd)
      return 1.3;
    return 1;
  }

  /**
   * 自动增加金币的上限+5（由每秒5秒10变为每5秒15）
   */
  public get goldAdd() {
    if (this.isGoldAdd)
      return 5;
    return 0;
  }
}